﻿{

    $project:
        {
 
            _id: "$_id",
            CompanyId: "$CompanyId",
            MatrixId: "$MatrixId",
            PeerGroupId: "$PeerGroupId",
            ParentGroupId: "$ParentGroupId",
            PeerGroupName: "$PeerGroupName",
            WorkingVersion : "$WorkingVersion",
            CompanyName : "$CompanyName ",


            E: "$E",
            S: "$S",
            G: "$G",
            P: "$P",


            E_1: "$E_1",
            E_2: "$E_2",
            E_3: "$E_3",

            G_1: "$G_1",
            G_2: "$G_2",
            G_3: "$G_3",

            S_1: "$S_1",
            S_2: "$S_2",
            S_3: "$S_3",
            S_4: "$S_4",
            S_5: "$S_5",


            CompanyScore: {
                $add: [
                       { $ifNull: [{ $multiply: [0.001, "$E.Score", "$E.Weight"] }, 0] },
                       { $ifNull: [{ $multiply: [0.001, "$S.Score", "$S.Weight"] }, 0] },
                       { $ifNull: [{ $multiply: [0.001, "$G.Score", "$G.Weight"] }, 0] },
                       { $ifNull: [{ $multiply: [0.001, "$P.Score", "$P.Weight"] }, 0] },
                ]
            }, 
            
            RankPeerGroup: -1,
            RankPercentPeerGroup: -1,
            RankParentPeerGroup: -1,
            RankParentPercentPeerGroup: -1,
        }

}